<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.iflysse.bbs.model.ReplyInfo"%>
<%@page import="java.util.List"%>
<%@page import="com.iflysse.bbs.model.NewsInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link style="text/css" rel="stylesheet" href="css/style.css">

<script type="text/javascript">
	$(function() {
		$("#login").click(function() {
			var url = $(this).attr("href");
			art.dialog.open(url, {
				id : "login",
				title : "用户登录",
				lock : true
			});
			return false;
		});
		
		$("#btnReply").click(function(){
			if($("#isLogin").val()=="false"){
				var url = "pages/login.jsp?returnUrl=pages/view_handler.jsp?newsid=" + $("#newsid").val();
				art.dialog.open(url, {
					id : "login",
					title : "用户登录",
					lock : true
				});
				return false;
			}
			
			if($("#reply").val()==""){
				art.dialog.alert('回复不能为空，请检查！');
				return false;
			}
			
		});
	});
</script>
</head>
<body>
	<div style="width: 600px; margin: 0 auto;">
		<%
			NewsInfo newsInfo = (NewsInfo) request.getAttribute("newsInfo");
			List<ReplyInfo> replyList = (List<ReplyInfo>) request
					.getAttribute("replyList");
		%>
		<div id="head">
			<%
				if (session.getAttribute("currentUser") == null) {
			%>
			<a
				href="pages/login.jsp?returnUrl=pages/view_handler.jsp?newsid=<%=newsInfo.getId()%>"
				id="login">登录</a>&nbsp;&nbsp;<a href="pages/register.jsp">注册</a>
			<%
				} else {
			%>
			<a href="pages/personal/home.jsp">我的账户</a>&nbsp;&nbsp;<a
				href="pages/cancel_handler.jsp">注销</a>
			<%
				}
			%>
		</div>

		<div
			style="border: solid 1px red; height: 20px; text-align: center; margin-top: 15px; font-size: 20px;">
			<%=newsInfo.getTitle()%>
		</div>
		<div
			style="border: solid 1px red; height: 20px; text-align: center; margin-top: 15px; font-size: 10px;">
			作者：<%=newsInfo.getUserName()%>&nbsp;&nbsp;&nbsp;&nbsp; 时间：
			<%
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			out.print(sdf.format(newsInfo.getDate()));
		%>
		</div>
		<div style="border: solid 1px red; margin-top: 15px; font-size: 15px;">
			&nbsp;&nbsp;&nbsp;&nbsp;<%=newsInfo.getContent()%>
		</div>


		<%
			if (replyList != null && replyList.size() > 0) {
		%>
		<div
			style="border: solid 1px blue; margin-top: 15px; font-size: 15px;">
			<div>回复：</div>

			<%
				for (ReplyInfo reply : replyList) {
			%>
			<div style="border-bottom: solid 1px gray; margin-top: 5px;">
				<%=reply.getUserName()%>[<%=sdf.format(reply.getDate())%>]：<%=reply.getContent()%>
			</div>
			<%
				}
			%>

		</div>
		<%
			}
		%>

		<div style="border: solid 1px red; margin-top: 15px; font-size: 15px;">
			<form action="pages/reply_handler.jsp" method="post">
				<input type="hidden" id="isLogin" value="<%=session.getAttribute("currentUser")==null ? false : true%>">
				<input type="hidden" id="newsid" name="newsid" value="<%=request.getParameter("newsid")%>">
				<input type="text" name="reply" id="reply"
					style="height: 30px; width: 250px;">
				&nbsp;&nbsp;&nbsp;&nbsp; 
				<input type="submit" id="btnReply"
					value="回复" style="height: 30px;">
			</form>
		</div>
</body>
</html>